package org.xxpay.pay.channel.saaspay;

import com.alibaba.fastjson.JSONObject;
import org.apache.commons.lang3.StringUtils;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.xxpay.core.common.constant.PayConstant;
import org.xxpay.core.common.domain.api.ApiBuilder;
import org.xxpay.core.common.domain.api.RefundOrderRes;
import org.xxpay.core.common.util.*;
import org.xxpay.core.common.vo.DBApplicationConfig;
import org.xxpay.core.entity.AlipayPayOrder;
import org.xxpay.core.entity.PayOrder;
import org.xxpay.core.entity.RefundOrder;
import org.xxpay.core.service.IPayOrderService;
import org.xxpay.pay.channel.BaseRefund;
import org.xxpay.pay.channel.recpay.RecpayConfig;
import org.xxpay.pay.channel.recpay.RecpayController;
import org.xxpay.pay.ctrl.common.BaseController;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import java.io.IOException;
import java.util.Date;
public class SaaspayController  extends BaseController {
    private static final MyLog _log = MyLog.getLog(RecpayController.class);

    /**
     * 查询订单payOrder
     * @param request
     * @return
     * @throws ServletException
     * @throws IOException
     */
//    @RequestMapping("/api/"+ SaaspayConfig.CHANNEL_NAME+"/refundOrder")
//    @ResponseBody
    public String refundOrder(HttpServletRequest request) {
        JSONObject po = getJsonParam(request);
        String payOrderId = getString(po, "payOrderId");
        _log.info("[退款订单]参数payOrderId={}", payOrderId);
        PayOrder payOrder = commonService.payOrderService.findByPayOrderId(payOrderId);
        String logPrefix = SaaspayConfig.CHANNEL_NAME + "订单退款";
        RefundOrder refundOrder = new RefundOrder();
        refundOrder.setPayOrderId(payOrderId);
        SaaspayRefundService srs = new SaaspayRefundService();
        int updateCount = commonService.refundOrderService.updateStatus4Complete(payOrderId);
        System.out.println(updateCount);
//        JSONObject retObj = srs.refund(refundOrder);
        //退款返回处理
//        if("SUCCESS".equals(retObj.getString("errCode"))){
//            //更新支付状态
//            commonService.refundOrderService.updateStatus4Complete(payOrderId);
//            //修改商户余额
//        }
//        _log.info("[退款订单]结果payOrderId={},retObj={}", payOrderId, retObj);
        return "retObj.toJSONString()";
    }






}
